<?php

require_once 'Zend/View/Helper/Abstract.php';

class  Core_View_Helper_Admin_IsAllowed extends Zend_View_Helper_Abstract
{
    /**
     * comments
     */
    public function isAllowed($module, $controller = null, $action = null)
    {
        $acl     = new Core_Acl();
        $mdlUser = new model_User();
        $user    = $mdlUser->getCurrentUser();
        //go from more specific to less specific
        $moduleLevel     = $module;
        $controllerLevel = $moduleLevel . '_' . $controller;
        $actionLevel     = $controllerLevel . '_' . $action;

        if (null != $action && $acl->has($actionLevel)) {
            $resource = $actionLevel;
        } else if (null != $controller && $acl->has($controllerLevel)) {
            $resource = $controllerLevel;
        } else {
            $resource = $moduleLevel;
        }
        if ($acl->has($resource)) {
            if ($acl->isAllowed($user->role, $resource)) {
                return true;
            }
        }
        return false;
    }
}